Getline (The GNU Awk User’s Guide)

您所在的位置:网站首页 awk read file Getline (The GNU Awk User’s Guide)

Getline (The GNU Awk User’s Guide)

#Getline (The GNU Awk User’s Guide)| 来源: 网络整理| 查看: 265

Next: Reading Input with a Timeout, Previous: Multiple-Line Records, Up: Reading Input Files   [Contents][Index]

4.10 Explicit Input with getline

So far we have been getting our input data from awk’s main input stream—either the standard input (usually your keyboard, sometimes the output from another program) or the files specified on the command line. The awk language has a special built-in command called getline that can be used to read input under your explicit control.

The getline command is used in several different ways and should not be used by beginners. The examples that follow the explanation of the getline command include material that has not been covered yet. Therefore, come back and study the getline command after you have reviewed the rest of this Web page and have a good knowledge of how awk works.

The getline command returns 1 if it finds a record and 0 if it encounters the end of the file. If there is some error in getting a record, such as a file that cannot be opened, then getline returns -1. In this case, gawk sets the variable ERRNO to a string describing the error that occurred.

If ERRNO indicates that the I/O operation may be retried, and PROCINFO["input", "RETRY"] is set, then getline returns -2 instead of -1, and further calls to getline may be attempted. See Retrying Reads After Certain Input Errors for further information about this feature.

In the following examples, command stands for a string value that represents a shell command.

NOTE: When --sandbox is specified (see Command-Line Options), reading lines from files, pipes, and coprocesses is disabled.

Using getline with No Arguments Using getline into a Variable Using getline from a File Using getline into a Variable from a File Using getline from a Pipe Using getline into a Variable from a Pipe Using getline from a Coprocess Using getline into a Variable from a Coprocess Points to Remember About getline Summary of getline Variants

Next: Reading Input with a Timeout, Previous: Multiple-Line Records, Up: Reading Input Files   [Contents][Index]



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3